/*
 *
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','feedback');

/*controller部分*/

//主要操作controller
authApp.controller("opinionEditController",function($scope,$http,$getQueryString,$timeout,$sce){
    $scope.schoolId = $getQueryString("schoolId");
    $scope.schoolName = decodeURIComponent(decodeURIComponent($getQueryString("schoolName")));
    $scope.expertId = $getQueryString("expertId");

    var queryMainApi=apis.queryOneFeedBack;
    var requestJson={'schoolId':$scope.schoolId,'expertId':$scope.expertId};
    $scope.queryMain=function(){
        $http({
            method:'post',
            url:queryMainApi,
            data:requestJson,
        }).success(function(response){
            if(response.code=="000000"){
                    $scope.workSurvey = response.data.survey;
                    $scope.impression = response.data.impression;
                    $scope.characteristic = response.data.characteristic;
                    $scope.suggest = response.data.suggest;

            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("网络出现故障，请确认网络是否连接");
        })
    }
    $scope.queryMain();

    //返回到前页面
    $scope.goback=function(){
        // if(window.confirm("是否确认返回？")){
        javascript:history.back(-1);
        // }
    }
    $scope.down=function() {
        return window.open('/views/investiga/table10.html?schoolId='+ $scope.schoolId +'&schoolName='+ $getQueryString("schoolName"))
    }
    $scope.saveData=function(){
        if(window.confirm("是否确认保存？")){
            var rJson={
                schoolId:$scope.schoolId,
                survey:$scope.workSurvey,
                impression:$scope.impression,
                characteristic:$scope.characteristic,
                suggest:$scope.suggest
            }

            $http({
                method:'post',
                url:apis.saveFeedBack,
                data:rJson,
            }).success(function(response){
                if(response.code=="000000"){
                    $scope.queryMain();
                    alert("保存数据成功！");
                }else{
                    alert(response.errorMsg);
                }
            }).error(function(){
                alert("网络出现故障，请确认网络是否连接");
            })
        }
    }

    function unUnicode(str)
    {
        return unescape(str.replace(/\/\//g, "%"));
    }

})

function toUnicode(str)
    {
        return escape(str).replace(/%/g,"\\").toLowerCase();
    }



